package com.example.exam.controller;

import com.example.exam.pojo.vo.ExamPaperVO.ExamPaperEditStandardVO;
import com.example.exam.pojo.vo.ExamPaperVO.ExamPaperStandardVO;
import com.example.exam.service.IExamPaperService;
import com.example.exam.tools.JsonPage;
import com.example.exam.tools.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@Api(tags = "试卷管理模块")
@RequestMapping("/api/admin/exam/paper")
public class ExamPaperController {

    @Autowired
    private IExamPaperService examService;

    @ApiOperation("分页查询试卷列表")
    @PostMapping({"/page","/taskExamPage"})
    public JsonResult<JsonPage<ExamPaperStandardVO>> pageList(@RequestBody ExamPaperStandardVO examPaperStandardVO) {
        log.debug("开始处理【分页查询试卷列表】的请求");
        JsonPage<ExamPaperStandardVO> listByPage = examService.getAllExamPaperByPage(examPaperStandardVO);
        return JsonResult.ok(listByPage);
    }

    @ApiOperation("根据id查询试卷,进入编辑界面")
    @PostMapping("/select/{id}")
    public JsonResult<ExamPaperEditStandardVO> select(@PathVariable Integer id){
        log.info("开始处理【根据id查询试卷】的请求");
        ExamPaperEditStandardVO editStandardById = examService.getEditStandardById(id);
        return JsonResult.ok(editStandardById);
    }

    @ApiOperation("添加/修改试卷")
    @PostMapping("/edit")
    public JsonResult<String> edit(@RequestBody @Validated ExamPaperEditStandardVO examPaperEditStandardVO){
        log.info("开始处理【添加/修改试卷】的请求");
        return JsonResult.ok(examService.edit(examPaperEditStandardVO));
    }

    @PostMapping("/delete/{id}")
    @ApiOperation("删除试卷")
    public JsonResult<String> delete(@PathVariable Integer id) {
        log.info("开始处理【删除试卷】的请求");
        examService.delete(id);
        return JsonResult.ok("删除试卷成功！");
    }

}
